package com.tz.cartelo.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.tz.cartelo.R;
import com.tz.cartelo.constant.Api;
import com.tz.cartelo.constant.Key;
import com.tz.cartelo.model.DataParams;
import com.tz.cartelo.result.Result;
import com.tz.cartelo.result.ResultGetCode;
import com.tz.common.util.LogUtil;
import com.tz.common.util.PreferencesUtils;

/**
 * Created by Administrator on 2017/4/16.
 */

public class Activity extends DataLoadActivity implements View.OnClickListener {
    private static final String TAG = "Activity";
    private Api mApi;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity;
    }

    @Override
    protected void init() {

    }

    @Override
    protected void initTitle() {
        ImageView titleBack = (ImageView) findViewById(R.id.title_back);
        titleBack.setVisibility(View.VISIBLE);
        titleBack.setOnClickListener(this);

        TextView titleText = (TextView) findViewById(R.id.title_text);
        titleText.setText(R.string.title);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_back:
                finish();
                break;
            default:
                break;
        }
    }

    @Override
    protected void initParams(DataParams params) {
        switch (mApi) {
            case GET_PHONE_CODE:
                params.addParam("phone", PreferencesUtils.getString(Key.PER_USER_PHONE, ""));
                params.addParam("userId", PreferencesUtils.getString(Key.PER_USER_ID, ""));
                break;
            default:
                break;
        }

    }

    @Override
    protected void disposeResult(Api api, String response) {
        LogUtil.d(TAG, response);
        switch (api) {
            case GET_PHONE_CODE:
                Result resultGetCode = fromJson(response, Result.class);
                if (!resultGetCode.isSuccess()) {
                    showToast(resultGetCode.getMessage());
                    return;
                }
                break;
            default:
                break;
        }
    }


}
